Repository navigation
fix(sourcemap): map columns inside code copied through unchanged - #744
Open
ashley-hunter wants to merge 1 commit into
Open
ashley-hunter wants to merge 1 commit into
ashley-hunter wants to merge 1 commit into
Conversation
Unchanged source segments were mapped only at the segment start and at column 0 of each line, so a position inside a line (an indented `throw`, a mid-line call) resolved to the start of its line. Tools that symbolicate a single position, such as a stack frame, lost the column for component code. Add a mapping at the start of each token within a line: each run of word characters and each punctuation character, skipping whitespace, with columns in UTF-16 code units as `LineColCursor` counts them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the compiler copies source through unchanged (class members, method bodies),
add_line_mappings_for_segmentonly added a mapping at the start of each segment and at column 0 of each line. Any position inside a line, such as an indentedthrowor a mid-line call, resolved to column 0 of its line.That is enough for a debugger stepping by line, but not for tools that resolve a single generated position, such as stack trace symbolication: the frame lands on the right line with no column, and tools that treat a column-0 mapping as missing show no mapping at all.
Fix
Within an unchanged segment, also add a mapping at the start of each token on a line: each run of word characters and each punctuation character. Whitespace gets no mapping. Columns advance in UTF-16 code units, as
LineColCursoralready counts them. The generated code is unchanged; only the map gains entries.Test
test_sourcemap_maps_columns_inside_unchanged_codecompiles a component and looks up the generated position of an indentedthrowand of a mid-line call that follows a non-BMP character (two UTF-16 code units). Each must map to its own source column. It also checks that a position inside a word or on whitespace resolves to the token it belongs to, so the map stays one entry per token rather than per character.throwmaps to(10, 0)instead of(10, 12).cargo test -p oxc_angular_compilerpasses.On a real component file, the map for the same output goes from 33 to 245 entries, and a stack frame inside a method body now resolves to its own column instead of column 0.